<template>
  <div>
    <div v-show="changeShow" style="margin:20px;">
      <el-button
        size="medium"
        align="center"
        type="primary"
        @click="goBack"
        >
        返回
      </el-button>
      <eChild :proId='proId' :changeShow='changeShow' ref="mychild" />
    </div>
    <div class="app-container"  v-show="!changeShow">
      <div class="filter-container">
        <span style="margin-left:3%">商品类型:</span>
        <el-cascader :options="areaData" clearable size="small" ref="area" :props="{value: 'catId', label: 'name',children:'proCatInfo'}" @change="areaChange" style="width:300px"></el-cascader>
        <span style="margin-left:3%">提交时间:</span>
        <el-date-picker
          v-model="value1"
          type="datetimerange"
          range-separator="——"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          size="small"
          value-format="yyyy-MM-dd HH:mm:ss">
        </el-date-picker>
        <span style="margin-left:3%">审核状态:</span>
        <el-select
          size="small"
          placeholder="请选择状态"
          clearable
          class="filter-item"
          style="width: 150px;margin-left:2%"
          v-model="listQuery.status"
        >
          <el-option v-for="item in calendarTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/>
        </el-select>
        <el-button
          size="small"
          class="filter-item"
          type="success"
          icon="el-icon-search"
          style="margin-left:3%"
          @click="handleFilter"
          >
          搜索
        </el-button>
      </div>

      <el-table
        :key="tableKey"
        :data="list"
        size="small"
        border
        fit
        highlight-current-row
        style="width: 100%;margin-top:1%"
      >
      <el-table-column type="index" label="序号">
      </el-table-column>
      <el-table-column label="商品类型" width="150px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.catName }}</span>
            <!-- <img :src="scope.row.imgUri" style="width:300px;height:200px" alt=""> -->
          </template>
        </el-table-column>
        <el-table-column label="商品名称" min-width="150px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.infoName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="提交时间" width="150px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.createTime }}</span>
          </template>
        </el-table-column>
        <el-table-column label="发布所属区/县" width="200px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.county }}</span>
          </template>
        </el-table-column>
        <el-table-column label="发布商户账户" width="150px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.shopNO }}</span>
          </template>
        </el-table-column>
        <el-table-column label="发布商户类型" width="100px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.shopType=='ONE_PERSON'?'个人商户':'企业商户' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="审核状态" width="100px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.status==='1'?'审核通过':'审核不通过' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="审核时间" width="200px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.passTime }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          align="center"
          width="100px"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="{ row }">
            <el-button
              size="small"
              align="center"
              type="primary"
              @click="handleUpdate(row)"
            >
              查看详情
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="listQuery.pageNum"
        :limit.sync="listQuery.pageSize"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
// 异步请求 delLly
import { getListPage} from '@/api/verifybusinessresult/index'
import Vue from 'vue'
import { parseTime } from '@/utils'
import {
  getAllCat,
} from "@/api/purchase/proCatReq";
import eChild from './child'
import Pagination from '@/components/Pagination' // 分页插件

const calendarTypeOptions = [
  { key: '1', display_name: '审核通过' },
  { key: '0', display_name: '审核不通过' },
]
const calendarTypeKeyValue = calendarTypeOptions.reduce((acc, cur) => {
  acc[cur.key] = cur.display_name
  return acc
}, {})

export default {
  inject:["reload"],
  components: { Pagination,eChild },
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'info',
        deleted: 'danger'
      }
      return statusMap[status]
    },
    typeFilter(type) {
      return calendarTypeKeyValue[type]
    },
  },
  data() {
    return {
      changeShow:false,
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        pageNum: 1,
        pageSize: 10,
        status:''
      },
      temp: {
        imgUri: '',
      },
      dialogFormVisible: false,
      calendarTypeOptions,
      dialogStatus: '',
      textMap: {
        update: '编辑',
        create: '添加',
      },
      proId:'',
      areaData:[],
      catId:"",
      value1:[]
    }
  },
  created() {
    this.getList()
    this.getCat()
  },
  methods: {
    //分类
    getCat(){
      var params={}
      getAllCat(params).then(response => {
        this.areaData=response.data
      });
    },
    areaChange(value){
      this.catId=value[1]
      console.log(value)
      console.log(this.$refs['area'].getCheckedNodes())
    },
    //返回首页
    goBack() {
        this.changeShow = false;
        this.getList()
    },
    getList() {
      this.listLoading = true
      if(this.value1!==null){
        if(this.value1.length>=2){
        this.beginDate=this.value1[0]
        this.endDate=this.value1[1]
        }else{
          this.beginDate=''
          this.endDate=''
        }
      }else{
        this.beginDate=''
        this.endDate=''
      }
      var params = {
        // pageConvert: true,
        pageNum: this.listQuery.pageNum-1,
        pageSize: this.listQuery.pageSize,
        status:this.listQuery.status,
        beginDate:this.beginDate,
        endDate:this.endDate,
        catId:this.catId
      }
      getListPage(params).then(response => {
        this.list = response.data.content
        this.total = response.data.totalElements
        // Just to simulate the time of the request
      })
    },
    handleFilter() {
      this.listQuery.pageNum = 1
      this.getList()
    },
    sortChange(data) {
      const { prop, order } = data
      if (prop === 'id') {
        this.sortByID(order)
      }
    },
    resetTemp() {
      this.temp = {
      }
    },
     handleUpdate(row) {
       // this.temp.timestamp = new Date(this.temp.timestamp)
      this.changeShow = true;
      this.proId=row.proId
      this.$refs.mychild.getList(this.proId)
      console.log(this.proId)
    },
    getSortClass: function(key) {
      const sort = this.listQuery.sort
      return sort === `+${key}`
        ? 'ascending'
        : sort === `-${key}`
          ? 'descending'
          : ''
    }
  }
}
</script>
<style scoped>

</style>